//
//  SingerMvViewController.m
//  Coco_Music
//
//  Created by dlios on 15-6-27.
//  Copyright (c) 2015年 寇广超. All rights reserved.
//

#import "SingerMvViewController.h"

@interface SingerMvViewController ()

@end

@implementation SingerMvViewController
-(void)dealloc
{
    [_myTableView release];
    [_myArray release];
    [super dealloc];
    
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.myTableView reloadData];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor=[UIColor whiteColor];
    self.myTableView= [[UITableView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-64) style:UITableViewStyleGrouped];

    self.myTableView.separatorStyle =UITableViewCellSeparatorStyleNone;
    self.myTableView.backgroundColor =[UIColor whiteColor];
    
    [self.view addSubview:self.myTableView];
    
    self.myTableView.delegate = self;
    self.myTableView.dataSource =self;
    self.HUD =[MBProgressHUD showHUDAddedTo:self.view animated:YES];
    self.HUD.labelText =@"正在加载,请稍后";
    [self.HUD show:YES];
    

    
    
    
    
}
#define SingerMVConnect @"http://api.dongting.com/song/singer/%ld/videos?"
#define SingerMVConnect1 @"page=1&app=ttpod&v=v7.9.4.2015052918&uid=&mid=iPad4%2C4&f=f320&s=s330&imsi=&hid=&splus=8.3&active=1&net=2&openudid=5df9002635a21cc5f7f660e71a16d1e35e5a04a0&idfa=B5F4461B-F9C7-4F1E-BA92-EB2E683311DF&utdid=VYEt7JjHCIUDAGowp1W3cSW3&alf=201200&bundle_id=com.ttpod.music"

-(void)setSingerId:(NSInteger)SingerId
{
    NSString *url =[NSString stringWithFormat:SingerMVConnect,SingerId];
    NSString *url1 =[NSString stringWithFormat:url,SingerMVConnect1];
    NSLog(@"puouoou %@",url1);
    
    [AFN_block NSString:url1 Blokc:^(id request) {
        NSMutableDictionary *myDic =[NSMutableDictionary dictionaryWithDictionary:request];
     
        self.myArray =[NSMutableArray array];
        NSMutableArray *dataArray =[myDic objectForKey:@"data"];
        for (NSMutableDictionary *dic in dataArray) {
           
            SingerMV *singMV =[[SingerMV alloc]init];
            singMV.SingerMvID =[[dic objectForKey:@"id"]integerValue];
            singMV.videoName =[dic objectForKey:@"videoName"];
            singMV.picUrl =[dic objectForKey:@"picUrl"];
            singMV.singerName =[dic objectForKey:@"singerName"];
            singMV.pickCount =[[dic objectForKey:@"pickCount"]integerValue];
            singMV.praiseCount =[[dic objectForKey:@"praiseCount"]integerValue];
            singMV.mvList =[dic objectForKey:@"mvList"];
            for (NSMutableDictionary *mvListDic in singMV.mvList) {
                singMV.url =[mvListDic objectForKey:@"url"];
            }
            [self.myArray addObject:singMV];
        }
        [self.HUD hide:YES];
        
        [self.myTableView reloadData];
        
    }];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.myTableView deselectRowAtIndexPath:indexPath animated:YES];
    MVPlayerViewController *mvVC = [[MVPlayerViewController alloc] init];
    
    mvVC.myMV =[self.myArray objectAtIndex:indexPath.row];
  mvVC.MvID =[[self.myArray objectAtIndex:indexPath.row]SingerMvID];
    [self.navigationController pushViewController:mvVC animated:YES];
    

}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.myArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier =@"cell";
    SingerMvTableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell ==nil) {
        cell =[[SingerMvTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
  
    cell.singMV =[self.myArray objectAtIndex:indexPath.row];
    cell.layer.transform = CATransform3DMakeScale(0.3, 0.3, 0.1);
    [UIView animateWithDuration:0.5 animations:^{
        
        cell.layer.transform = CATransform3DMakeScale(1, 1, 0.1);
        
    }];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 120;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
